using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace Redirect404 {
    public class Migrations : DataMigrationImpl {

        public int Create() {
			// Creating table RedirectPartRecord
			SchemaBuilder.CreateTable("RedirectPartRecord", table => table
				.ContentPartRecord()
				.Column("RequestedUrl", DbType.String)
				.Column("DestUrl", DbType.String)
				.Column("UseRegex", DbType.Boolean)
			);

            return 1;
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.AlterTable("RedirectPartRecord", table => table.AddColumn("RedirectType", DbType.String));
            SchemaBuilder.AlterTable("RedirectPartRecord", table => table.AddColumn("ProcessOrder", DbType.Int32));
            return 2;
        }

        public int UpdateFrom2()
        {
            ContentDefinitionManager.AlterTypeDefinition("RedirectItem", cfg => cfg.WithPart("RedirectPart"));
            return 3;
        }

    }
}